package com.dys.controller;

import com.dys.entity.Emp;
import com.dys.mapper.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @className: com.dys.controller.EmpController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/11/27 23:12
 */
@RestController
public class EmpController {

    @Autowired
    private EmpMapper empMapper;

    /**
     * 请选择员工信息
     *
     * @return 描述消息
     */
    @GetMapping("/selectEmp")
    public String selectEmp() {
        List<Emp> emps = empMapper.selectEmp();
        for (Emp Emp : emps) {
            System.out.println(Emp);
        }
        return "查询成功";
    }

    // 根据id选择用户
    @GetMapping("/selectEmpById")
    public String selectEmpById() {
        Emp emp = empMapper.selectEmpById(5);
        System.out.println(emp);
        return "根据id查询员工信息";
    }

    // 添加员工信息
    @GetMapping("/addEmp")
    public String addEmp() {
        empMapper.addEmp(new Emp(6, "雷军"));
        return "添加员工";
    }

    // 修改员工信息
    @GetMapping("/updateEmp")
    public String updateEmp() {
        empMapper.updateEmp(new Emp(6, "余承东"));
        return "修改员工信息";
    }

    // 根据id删除用户
    @GetMapping("/deleteEmp")
    public String deleteEmp() {
        empMapper.deleteEmp(6);
        return "删除员工信息";
    }
}
